<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>Zend_Service_Amazon_Sqs - Zend Framework Manual</title>

    <link href="../css/shCore.css" rel="stylesheet" type="text/css" />
    <link href="../css/shThemeDefault.css" rel="stylesheet" type="text/css" />
    <link href="../css/styles.css" media="all" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Zend Framework</h1>
<h2>Programmer's Reference Guide</h2>
<ul>
    <li><a href="../en/zend.service.amazon.sqs.html">Inglês (English)</a></li>
    <li><a href="../pt-br/zend.service.amazon.sqs.html">Português Brasileiro (Brazilian Portuguese)</a></li>
</ul>
<table width="100%">
    <tr valign="top">
        <td width="85%">
            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.service.amazon.s3.html">Zend_Service_Amazon_S3</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.service.html">Zend_Service</a></span><br />
                        <span class="home"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.service.audioscrobbler.html">Zend_Service_Audioscrobbler</a></div>
                    </td>
                </tr>
            </table>
<hr />
<div id="zend.service.amazon.sqs" class="section"><div class="info"><h1 class="title">Zend_Service_Amazon_Sqs</h1></div>
    

    <div class="section" id="zend.service.amazon.sqs.introduction"><div class="info"><h1 class="title">Introduction</h1></div>
        

        <p class="para">
            <a href="http://aws.amazon.com/sqs/" class="link external">&raquo; Amazon Simple Queue Service
                (Amazon SQS)</a> offers a reliable, highly scalable, hosted
            queue for storing messages as they travel between computers. By
            using Amazon SQS, developers can simply move data between
            distributed components of their applications that perform different
            tasks, without losing messages or requiring each component to be
            always available. Amazon SQS makes it easy to build an automated
            workflow, working in close conjunction with the Amazon Elastic
            Compute Cloud (Amazon EC2) and the other <acronym class="acronym">AWS</acronym> infrastructure web
            services.
        </p>

        <p class="para">
            Amazon SQS works by exposing Amazon&#039;s web-scale messaging
            infrastructure as a web service. Any computer on the Internet can
            add or read messages without any installed software or special
            firewall configurations. Components of applications using Amazon SQS
            can run independently, and do not need to be on the same network,
            developed with the same technologies, or running at the same time.
        </p>
    </div>

    <div class="section" id="zend.service.amazon.sqs.registering"><div class="info"><h1 class="title">Registering with Amazon SQS</h1></div>
        

        <p class="para">
            Before you can get started with
            <span class="classname">Zend_Service_Amazon_Sqs</span>, you must first
            register for an account. Please see the <a href="http://aws.amazon.com/sqs/faqs/" class="link external">&raquo; SQS FAQ</a> page on
            the Amazon website for more information.
        </p>

        <p class="para">
            After registering, you will receive an application key and a secret key.
            You will need both to access the SQS service.
        </p>
    </div>

    <div class="section" id="zend.service.amazon.sqs.apiDocumentation"><div class="info"><h1 class="title">API Documentation</h1></div>
        

        <p class="para">
            The <span class="classname">Zend_Service_Amazon_Sqs</span> class provides
            the <acronym class="acronym">PHP</acronym> wrapper to the Amazon SQS REST interface. Please consult the
            <a href="http://developer.amazonwebservices.com/connect/kbcategory.jspa?categoryID=31" class="link external">&raquo; Amazon
                SQS documentation</a> for detailed description of the
            service. You will need to be familiar with basic concepts in order
            to use this service.
        </p>
    </div>

    <div class="section" id="zend.service.amazon.sqs.features"><div class="info"><h1 class="title">Features</h1></div>
        

        <p class="para">
            <span class="classname">Zend_Service_Amazon_Sqs</span> provides the
            following functionality:
        </p>

        <ul class="itemizedlist">
            <li class="listitem">
                <p class="para">
                    A single point for configuring your amazon.sqs
                    authentication credentials that can be used across the
                    amazon.sqs namespaces.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    A proxy object that is more convenient to use than an <acronym class="acronym">HTTP</acronym>
                    client alone, mostly removing the need to manually construct
                    <acronym class="acronym">HTTP</acronym> POST requests to access the REST service.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    A response wrapper that parses each response body and throws
                    an exception if an error occurred, alleviating the need to
                    repeatedly check the success of many commands.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    Additional convenience methods for some of the more common
                    operations.
                </p>
            </li>
        </ul>
    </div>

    <div class="section" id="zend.service.amazon.sqs.storing-your-first"><div class="info"><h1 class="title">Getting Started</h1></div>
        

        <p class="para">
            Once you have registered with Amazon SQS, you&#039;re ready to create
            your queue and store some messages on SQS. Each queue can contain
            unlimited amount of messages, identified by name.
        </p>

        <p class="para">
            The following example demonstrates creating a queue, storing and
            retrieving messages.
        </p>

        <div class="example" id="zend.service.amazon.sqs.storing-your-first.example"><div class="info"><p><b>Example #1 Zend_Service_Amazon_Sqs Usage Example</b></p></div>
            

            <pre class="programlisting brush: php">
$sqs = new Zend_Service_Amazon_Sqs($my_aws_key, $my_aws_secret_key);

$queue_url = $sqs-&gt;create(&#039;test&#039;);

$message = &#039;this is a test&#039;;
$message_id = $sqs-&gt;send($queue_url, $message);

foreach ($sqs-&gt;receive($queue_url) as $message) {
    echo $message[&#039;body&#039;].&#039;&lt;br/&gt;&#039;;
}
</pre>

        </div>

        <p class="para">
            Since the <span class="classname">Zend_Service_Amazon_Sqs</span> service
            requires authentication, you should pass your credentials (AWS key
            and secret key) to the constructor. If you only use one account,
            you can set default credentials for the service:
        </p>

        <pre class="programlisting brush: php">
Zend_Service_Amazon_Sqs::setKeys($my_aws_key, $my_aws_secret_key);
$sqs = new Zend_Service_Amazon_Sqs();
</pre>

    </div>

    <div class="section" id="zend.service.amazon.sqs.queues"><div class="info"><h1 class="title">Queue operations</h1></div>
        

        <p class="para">
            All messages SQS are stored in queues. A queue has to be created
            before any message operations. Queue names must be unique under your
            access key and secret key.
        </p>

        <p class="para">
            Queue names can contain lowercase letters, digits, periods (.),
            underscores (_), and dashes (-). No other symbols allowed. Queue
            names can be a maximum of 80 characters.
        </p>

        <ul class="itemizedlist">
            <li class="listitem">
                <p class="para">
                     <span class="methodname">create()</span> creates a new queue.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">delete()</span> removes all messages in
                    the queue.
                </p>

                <div class="example" id="zend.service.amazon.sqs.queues.removalExample"><div class="info"><p><b>Example #2 Zend_Service_Amazon_Sqs Queue Removal Example</b></p></div>
                    

                    <pre class="programlisting brush: php">
$sqs = new Zend_Service_Amazon_Sqs($my_aws_key, $my_aws_secret_key);
$queue_url = $sqs-&gt;create(&#039;test_1&#039;);
$sqs-&gt;delete($queue_url);
</pre>

                </div>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">count()</span> gets the approximate number
                    of messages in the queue.
                </p>

                <div class="example" id="zend.service.amazon.sqs.queues.countExample"><div class="info"><p><b>Example #3 Zend_Service_Amazon_Sqs Queue Count Example</b></p></div>
                    

                    <pre class="programlisting brush: php">
$sqs = new Zend_Service_Amazon_Sqs($my_aws_key, $my_aws_secret_key);
$queue_url = $sqs-&gt;create(&#039;test_1&#039;);
$sqs-&gt;send($queue_url, &#039;this is a test&#039;);
$count = $sqs-&gt;count($queue_url); // Returns &#039;1&#039;
</pre>

                </div>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">getQueues()</span> returns the list of the
                    names of all queues belonging to the user.
                </p>

                <div class="example" id="zend.service.amazon.sqs.queues.listExample"><div class="info"><p><b>Example #4 Zend_Service_Amazon_Sqs Queue Listing Example</b></p></div>
                    

                    <pre class="programlisting brush: php">
$sqs = new Zend_Service_Amazon_Sqs($my_aws_key, $my_aws_secret_key);
$list = $sqs-&gt;getQueues();
foreach($list as $queue) {
   echo &quot;I have queue $queue\n&quot;;
}
</pre>

                </div>
            </li>
        </ul>
    </div>

    <div class="section" id="zend.service.amazon.sqs.messages"><div class="info"><h1 class="title">Message operations</h1></div>
        

        <p class="para">
            After a queue is created, simple messages can be sent into the queue
            then received at a later point in time. Messages can be up to 8KB in
            length. If longer messages are needed please see <a href="http://framework.zend.com/manual/en/zend.service.amazon.s3.html" class="link external">&raquo; S3</a>.
            There is no limit to the number of messages a queue can contain.
        </p>

        <ul class="itemizedlist">
            <li class="listitem">
                <p class="para">
                     <span class="methodname">sent($queue_url, $message)</span> send the
                    <var class="varname">$message</var> to the <var class="varname">$queue_url</var> SQS
                    queue <acronym class="acronym">URL</acronym>.
                </p>

                <div class="example" id="zend.service.amazon.sqs.messages.sendExample"><div class="info"><p><b>Example #5 Zend_Service_Amazon_Sqs Message Send Example</b></p></div>
                    

                    <pre class="programlisting brush: php">
$sqs = new Zend_Service_Amazon_Sqs($my_aws_key, $my_aws_secret_key);
$queue_url = $sqs-&gt;create(&#039;test_queue&#039;);
$sqs-&gt;send($queue_url, &#039;this is a test message&#039;);
</pre>

                </div>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">receive($queue_url)</span> retrieves
                    messages from the queue.
                </p>

                <div class="example" id="zend.service.amazon.sqs.messages.receiveExample"><div class="info"><p><b>Example #6 Zend_Service_Amazon_Sqs Message Receive Example</b></p></div>
                    

                    <pre class="programlisting brush: php">
$sqs = new Zend_Service_Amazon_Sqs($my_aws_key, $my_aws_secret_key);
$queue_url = $sqs-&gt;create(&#039;test_queue&#039;);
$sqs-&gt;send($queue_url, &#039;this is a test message&#039;);
foreach ($sqs-&gt;receive($queue_url) as $message) {
    echo &quot;got message &quot;.$message[&#039;body&#039;].&#039;&lt;br/&gt;&#039;;
}
</pre>

                </div>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">deleteMessage($queue_url, $handle)</span>
                    deletes a message from a queue. A message must first be
                    received using the  <span class="methodname">receive()</span> method
                    before it can be deleted.
                </p>

                <div class="example" id="zend.service.amazon.sqs.messages.deleteExample"><div class="info"><p><b>Example #7 Zend_Service_Amazon_Sqs Message Delete Example</b></p></div>
                    

                    <pre class="programlisting brush: php">
$sqs = new Zend_Service_Amazon_Sqs($my_aws_key, $my_aws_secret_key);
$queue_url = $sqs-&gt;create(&#039;test_queue&#039;);
$sqs-&gt;send($queue_url, &#039;this is a test message&#039;);
foreach ($sqs-&gt;receive($queue_url) as $message) {
    echo &quot;got message &quot;.$message[&#039;body&#039;].&#039;&lt;br/&gt;&#039;;

    if ($sqs-&gt;deleteMessage($queue_url, $message[&#039;handle&#039;])) {
        echo &quot;Message deleted&quot;;
    }
    else {
        echo &quot;Message not deleted&quot;;
    }
}
</pre>

                </div>
            </li>
       </ul>
    </div>
</div>
        <hr />

            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.service.amazon.s3.html">Zend_Service_Amazon_S3</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.service.html">Zend_Service</a></span><br />
                        <span class="home"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.service.audioscrobbler.html">Zend_Service_Audioscrobbler</a></div>
                    </td>
                </tr>
            </table>
</td>
        <td style="font-size: smaller;" width="15%"> <style type="text/css">
#leftbar {
	float: left;
	width: 186px;
	padding: 5px;
	font-size: smaller;
}
ul.toc {
	margin: 0px 5px 5px 5px;
	padding: 0px;
}
ul.toc li {
	font-size: 85%;
	margin: 1px 0 1px 1px;
	padding: 1px 0 1px 11px;
	list-style-type: none;
	background-repeat: no-repeat;
	background-position: center left;
}
ul.toc li.header {
	font-size: 115%;
	padding: 5px 0px 5px 11px;
	border-bottom: 1px solid #cccccc;
	margin-bottom: 5px;
}
ul.toc li.active {
	font-weight: bold;
}
ul.toc li a {
	text-decoration: none;
}
ul.toc li a:hover {
	text-decoration: underline;
}
</style>
 <ul class="toc">
  <li class="header home"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></li>
  <li class="header up"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></li>
  <li class="header up"><a href="reference.html">Refer&ecirc;ncia do Zend Framework</a></li>
  <li class="header up"><a href="zend.service.html">Zend_Service</a></li>
  <li><a href="zend.service.introduction.html">Introdu&ccedil;&atilde;o</a></li>
  <li><a href="zend.service.akismet.html">Zend_Service_Akismet</a></li>
  <li><a href="zend.service.amazon.html">Zend_Service_Amazon</a></li>
  <li><a href="zend.service.amazon.ec2.html">Zend_Service_Amazon_Ec2</a></li>
  <li><a href="zend.service.amazon.ec2.instance.html">Zend_Service_Amazon_Ec2: Instances</a></li>
  <li><a href="zend.service.amazon.ec2.windows.instance.html">Zend_Service_Amazon_Ec2: Windows Instances</a></li>
  <li><a href="zend.service.amazon.ec2.reserved.instance.html">Zend_Service_Amazon_Ec2: Reserved Instances</a></li>
  <li><a href="zend.service.amazon.ec2.cloudwatch.html">Zend_Service_Amazon_Ec2: CloudWatch Monitoring</a></li>
  <li><a href="zend.service.amazon.ec2.images.html">Zend_Service_Amazon_Ec2: Amazon Machine Images (AMI)</a></li>
  <li><a href="zend.service.amazon.ec2.ebs.html">Zend_Service_Amazon_Ec2: Elastic Block Storage (EBS)</a></li>
  <li><a href="zend.service.amazon.ec2.elasticip.html">Zend_Service_Amazon_Ec2: Elastic IP Addresses</a></li>
  <li><a href="zend.service.amazon.ec2.keypairs.html">Zend_Service_Amazon_Ec2: Keypairs</a></li>
  <li><a href="zend.service.amazon.ec2.zones.html">Zend_Service_Amazon_Ec2: Regions and Availability Zones</a></li>
  <li><a href="zend.service.amazon.ec2.securitygroups.html">Zend_Service_Amazon_Ec2: Security Groups</a></li>
  <li><a href="zend.service.amazon.s3.html">Zend_Service_Amazon_S3</a></li>
  <li class="active"><a href="zend.service.amazon.sqs.html">Zend_Service_Amazon_Sqs</a></li>
  <li><a href="zend.service.audioscrobbler.html">Zend_Service_Audioscrobbler</a></li>
  <li><a href="zend.service.delicious.html">Zend_Service_Delicious</a></li>
  <li><a href="zend.service.developergarden.html">Zend_Service_DeveloperGarden</a></li>
  <li><a href="zend.service.ebay.html">Zend_Service_Ebay</a></li>
  <li><a href="zend.service.ebay.finding.html">Zend_Service_Ebay_Finding</a></li>
  <li><a href="zend.service.flickr.html">Zend_Service_Flickr</a></li>
  <li><a href="zend.service.livedocx.html">Zend_Service_LiveDocx</a></li>
  <li><a href="zend.service.nirvanix.html">Zend_Service_Nirvanix</a></li>
  <li><a href="zend.service.recaptcha.html">Zend_Service_ReCaptcha</a></li>
  <li><a href="zend.service.short-url.html">Zend_Service_ShortUrl</a></li>
  <li><a href="zend.service.simpy.html">Zend_Service_Simpy</a></li>
  <li><a href="zend.service.slideshare.html">Zend_Service_SlideShare</a></li>
  <li><a href="zend.service.strikeiron.html">Zend_Service_StrikeIron</a></li>
  <li><a href="zend.service.strikeiron.bundled-services.html">Zend_Service_StrikeIron: Bundled Services</a></li>
  <li><a href="zend.service.strikeiron.advanced-uses.html">Zend_Service_StrikeIron: Advanced Uses</a></li>
  <li><a href="zend.service.technorati.html">Zend_Service_Technorati</a></li>
  <li><a href="zend.service.twitter.html">Zend_Service_Twitter</a></li>
  <li><a href="zend.service.windowsazure.html">Zend_Service_WindowsAzure</a></li>
  <li><a href="zend.service.windowsazure.storage.blob.html">Zend_Service_WindowsAzure_Storage_Blob</a></li>
  <li><a href="zend.service.windowsazure.diagnostics.manager.html">Zend_Service_WindowsAzure_Diagnostics_Manager</a></li>
  <li><a href="zend.service.windowsazure.storage.queue.html">Zend_Service_WindowsAzure_Storage_Queue</a></li>
  <li><a href="zend.service.windowsazure.storage.table.html">Zend_Service_WindowsAzure_Storage_Table</a></li>
  <li><a href="zend.service.yahoo.html">Zend_Service_Yahoo</a></li>
 </ul>
 </td>
    </tr>
</table>

<script type="text/javascript" src="../js/shCore.js"></script>
<script type="text/javascript" src="../js/shAutoloader.js"></script>
<script type="text/javascript" src="../js/main.js"></script>

</body>
</html>